package com.itheima.controller;
import com.itheima.Utils.AliyunOSSUtils;
import com.itheima.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
public class UploadController {
    private String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";
    private String bucketName = "web1122";
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
        log.info("文件上传成功");
        String oldUpload = file.getOriginalFilename();
        String extName = oldUpload.substring(oldUpload.lastIndexOf("."));
        String imgurl = AliyunOSSUtils.upload(endpoint, bucketName, file.getBytes(), extName);
        return Result.success(imgurl);
    }
}
